package cn.pkubangbang.demo.democontact.controller;

import cn.pkubangbang.demo.democontact.entity.Person;
import cn.pkubangbang.demo.democontact.exceptions.ResultNotFoundException;
import cn.pkubangbang.demo.democontact.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: zhangzhenbang@k2data.com.cn
 * @Date: 2018-08-23 17:30
 */
@Controller
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private PersonService personService;

    @GetMapping("/{id}")
    @ResponseBody
    public Person getPersonById(@PathVariable("id") Integer id) {
        Person who = personService.getPersonById(id);
        if (who == null) {
            throw new ResultNotFoundException("get person by id["+ id +"], not found.");
        }
        return who;
    }



}
